import AddBuyType from '../../common/add-buy-type/add-buy-type.vue'
import UpdateBuyType from '../../common/update-buy-type/update-buy-type.vue'
import { showMsg, getBuyTypeList } from '../../../../../vuex/action.js'
import extend from 'extend'

export default {
  data() {
    return {
      buytypeList: [],
      pages: {
        start: 0,
        limit: 99999
      }
    }
  },
  methods: {
    deepClone(obj) {
      return extend(true, {}, obj)
    },
    getBuyTypeList() {
      this.xGetBuyTypeList({
        start: this.pages.start,
        limit: this.pages.limit,
        type: this.payType
      }).then((res) => {
        this.buytypeList = res.data.list
      }).catch((res) => {
        this.xShowMsg({
          type: 'danger',
          content: res.error_msg
        })
      })
    }
  },
  events: {
    on_refresh_list() {
      this.getBuyTypeList()
    }
  },
  vuex: {
    actions: {
      xShowMsg: showMsg,
      xGetBuyTypeList: getBuyTypeList
    },
    getters: {
      payType: state => state.payType
    }
  },
  components: {
    'add-buy-type': AddBuyType,
    'update-buy-type': UpdateBuyType
  },
  ready() {
    this.getBuyTypeList()
  }
}
